package com.yolo.yolorpc.server;


import io.vertx.core.Vertx;

/**
 * @Program: RPC
 * @description: vert.x服务器
 * @author: yolo
 * @create: 2025-04-18 16:51
 **/
public class VertxHttpServer implements HttpServer{

    @Override
    public void doStart(int port) {
        // 创建vert.x实例
        Vertx vertx = Vertx.vertx();

        // 创建http服务器
        io.vertx.core.http.HttpServer httpServer = vertx.createHttpServer();
        // 监听端口并处理请求
        httpServer.requestHandler(new HttpServerHandler());

        // 启动http服务器并监听端口
        httpServer.listen(port, result -> {
            if (result.succeeded()) {
                System.out.println("server now is listening on port" + port);
            }else {
                System.err.println("Failed to start server:" + result.cause());
            }
        });
    }
}
